package com.bw.ivideo

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.bw.ivideo.testmvi.model.entity.VideoEntity
import com.bw.ivideo.testmvi.net.Api
import com.bw.lib_common.utils.LoggerUtils
import com.bw.lib_log.crash.CrashHandler
import com.bw.lib_net.RetrofitManager
import com.bw.lib_net.entity.ResponseEntity
import retrofit2.Call
import retrofit2.Response

class MainActivity : AppCompatActivity() {

    companion object{
        const val TAG = "MainActivity"
    }

    init {
        CrashHandler.getInstance().init(this)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        LoggerUtils.d(TAG, "测试")

        RetrofitManager.instance.createService(Api::class.java)
            .getVideos(1,10)
            .enqueue(object : retrofit2.Callback<ResponseEntity<MutableList<VideoEntity>>> {
                override fun onResponse(
                    call: Call<ResponseEntity<MutableList<VideoEntity>>>,
                    response: Response<ResponseEntity<MutableList<VideoEntity>>>
                ) {
                    LoggerUtils.d(TAG, "ok ${response.body()?.data}")
                }

                override fun onFailure(
                    call: Call<ResponseEntity<MutableList<VideoEntity>>>,
                    t: Throwable
                ) {
                    LoggerUtils.d(TAG, "error ${t.message}")
                }

            })



    }

    fun crash(view: View) {
        try {
            LoggerUtils.d(TAG, "测试下 ${10/0}")
        }catch (e:Exception){
            CrashHandler.getInstance().uncaughtException(Thread(),e)
        }

    }

    fun anr(view: View) {
        Thread.sleep(20*1000)
    }

}